<?php

class medal_recept_model extends CI_Model {

    function MedalReceptModel() {
        parent::Model();
    }

    function get_fname($uid) {
        $this->db->select("of.function_ID,off.name");
        $this->db->from("Office_Function as off");
        $this->db->join("Office as of", "off.ID = of.function_ID", "inner");
        $this->db->where('of.name', $uid);
        $result = $this->db->get();
        return $result->row_array();
    }

    function select_function() {
        /* return
          $this -> db -> select('
          off.name,
          off.ID,
          of.function_ID
          ')
          -> from('Official_Function as off')
          -> join('Official as of', 'off.ID = of.id')
          -> where($data)
          -> order_by('off.name')
          -> get()
          -> result()
          ; */

        return
                        $this->db->order_by('name')
                        ->get('Official_Function')
                        ->result_array();
        ;
    }

    function do_new_recept() {
        $query = $this->db->get_where('Officer', array('name' => check_post('name')));
        if (!$query->num_rows) {
            $this->db->insert('Officer', array(
                'function_ID' => check_post('status'),
                'name' => check_post('name'),
                'note' => check_post('note')
            ));
            combine_session('success', 'បន្ថែមមន្ត្រីថ្មីបានជោគជ័យ');
        } else {
            combine_session('failed', 'ឈ្មោះនេះមានរួចហើយនៅក្នុងប្រព័ន្ធ');
        }
        redirect(site_url('/medal_recept/'));
    }

}

?>